﻿addLoadEvent(bindPostMessageEvent);
var ASPNETFORM={autoString:"ctl00$ContenBody$postMessage$"}

function bindPostMessageEvent(){
    var postMessageForm=$fm("aspnetForm");
    initPostMessage.call(postMessageForm);
}


function initPostMessage(){
    var padN=ASPNETFORM.autoString;
    this.InputText=[
    this[padN+"userNameTb"],
    this[padN+"vCodeTb"],
    this[padN+"msgTb"],
    ]
    bindMulitObjectEvent.call(this.InputText,["onfocus", FocusInputText],["onblur", BlurInputText],["onchange", ChangeInputText]);
    this.onsubmit=submitPostMessage;
}

function submitPostMessage(){
    var padN=ASPNETFORM.autoString;
    if(!CheckLength.call(this[padN+"userNameTb"],3,15)){
        alert("用户名为3-15位");
        return false;
    }
    if(!CheckLength.call(this[padN+"vCodeTb"],5,5)){
        alert("验证码长度不对");
        return false;
    }
    if(!CheckLength.call(this[padN+"msgTb"],3,1000)){
        alert("留言至少要3个字符");
        return false;
    }
    return true;
}

function FocusInputText(){
    this.className="focusinput";
}
function BlurInputText(){
    this.className="input";
}
//暂时不做即时;
function ChangeInputText(){
   /* var padN="ctl00$contentbody$";
    
    switch(this.name){
        case padN+"titleTb" :
            CheckLength.call(this,3,15);
            break;
        case padN+"widthTb":
        case padN+"heightTb":
            CheckNaN.call(this);
            break;
        default:
            break;
    }*/
}

function CheckLength(min,max){
    if(this.value.length < min || this.value.length > max)return false;
    return true;
}
function CheckNaN(){
    if(isNaN(this.value)){
        return false;
    }
    return true
}


function bindMulitObjectEvent(){
    for(var i=0;i<this.length;i++){
        bindObjectMulitEvent.apply(this[i],arguments);
    }
}
function bindObjectMulitEvent(){
    for(var i=0;i<arguments.length;i++){
        this[arguments[i][0]]=arguments[i][1];
    }
}